﻿using WebAndLoadTestPluginsAndRules;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;

namespace HtmlTagInnerTextTests
{
    /// <summary>
    ///This is a test class for HtmlTagInnerTextParserTest and is intended
    ///to contain all HtmlTagInnerTextParserTest Unit Tests
    ///</summary>
    [TestClass()]
    public class HtmlTagInnerTextParserTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {
            PageManager.Initialize(testContext);
        }
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for GetInnerTextForHtmlTags
        ///</summary>
        [DeploymentItem("webtestrulestests\\testpages\\testpage.htm"), TestMethod()]
        public void GetInnerTextForHtmlTagsTest()
        {
            string documentContent;
            PageManager.Instance.LoadPage("TestPage.htm", out documentContent);

            HtmlTagInnerTextParser parser = new HtmlTagInnerTextParser(documentContent);
            foreach (InnerText innerText in parser.GetInnerTextForHtmlTags("div", "id", "12", true, true, true))
            {
                Assert.AreEqual("My first div My second div my first cont here is some more tesdt", innerText.Value);
            }

            foreach (InnerText innerText in parser.GetInnerTextForHtmlTags("div", "id", "12", true, true, false))
            {
                Assert.AreEqual("   My first   div My second div               my first cont        \r\nhere is some more tesdt \r\n", innerText.Value);
            }

            foreach (InnerText innerText in parser.GetInnerTextForHtmlTags("div", "id", "12", true, false, true))
            {
                Assert.AreEqual("My first div <div id=22>My second div</div> my first cont here is some more tesdt", innerText.Value);
            }

            foreach (InnerText innerText in parser.GetInnerTextForHtmlTags("div", "id", "12", true, false, false))
            {
                Assert.AreEqual("   My first   div <div id=22>My second div</div>               my first cont        \r\nhere is some more tesdt \r\n", innerText.Value);
            }

            foreach (InnerText myurl in parser.GetInnerTextForHtmlTags("a", "href", "test.html", true, false, false))
            {
                Assert.AreEqual("Some Url Content", myurl.Value);
            }

            List<InnerText> spans = new List<InnerText>();
            foreach (InnerText innerText in parser.GetInnerTextForHtmlTags("span", false, false, true))
            {
                spans.Add(innerText);
            }
            Assert.AreEqual(2, spans.Count);
            Assert.AreEqual("<i>My span <p>content<p> hello</p>aa</p>asd</i>", spans[0].Value);
            Assert.AreEqual("Hello", spans[1].Value);
        }
    }
}
